import sys
file = open("input.txt")
data = file.readlines()
N, K = map(int, data[0].split())
box = [-1] + list(map(int, data[1].split()))
num = [[0] for i in range(K + 1)]
for i in range(1, N + 1):
    for j in range(1, K + 1):
        if box[i] != j:
            num[j] += [num[j][i - 1]]
        else:
            num[j] += [num[j][i - 1] + 1]
ans = 0
for i in range(1, N + 1):
    for j in range(1, N + 1):
        for m in range(1, K + 1):
            if i >= j:
                if (num[m][i] - num[m][j - 1]) / ((i - j) + 1) > 0.5:
                    ans += 1
                    break
print(ans)